package org.apache.commons.graph.bean

import com.gitee.wsl.text.format.format
import org.apache.commons.graph.utils.Objects

class LabeledWeightedEdge<V,W>(
    label: String,
    source: V, target: V,
    val weight: W
) : LabeledEdge<V>(label,source,target) {

    /**
     * {@inheritDoc}
     */
    override fun equals(obj: Any?): Boolean {
        if (obj == null) {
            return false
        }

        if (this === obj) {
            return true
        }

        if (!super.equals(obj)) {
            return false
        }

        if (this::class != obj::class) {
            return false
        }
        val other = obj as LabeledWeightedEdge<*,*>
        if (source != other.source) return false
        if (target != other.target) return false

        return Objects.eq(weight, other.weight)
    }

    /**
     * {@inheritDoc}
     */
    override fun hashCode(): Int {
        return Objects.hash(super.hashCode(), 31, weight)
    }

    /**
     * {@inheritDoc}
     */
    override fun toString(): String {
        return String.format("%s( %s )", label, weight)
    }

}
